package maze.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import maze.model.type.Face;
import maze.model.type.Wall;

public class Cell
{
	public Pair position;
	public Map<Face, Wall> walls;

	public Cell()
	{
		this.walls = new HashMap<Face, Wall>();
	}

	public Cell(Pair position)
	{
		this.position = position;
		this.walls = new HashMap<Face, Wall>();
	}

	/**
	 * @return the position of the adjacent cell according to the face
	 */
	public Pair adjacentCellPosition(Face face)
	{
		switch (face)
		{
			case NORTH:
				return new Pair(position.x, position.y + 1);
			case SOUTH:
				return new Pair(position.x, position.y - 1);
			case WEST:
				return new Pair(position.x - 1, position.y);
			case EAST:
				return new Pair(position.x + 1, position.y);
			default:
				return null;
		}
	}

	/**
	 * @return the faces of the walls with blocked status
	 */
	public List<Face> blockedFaces()
	{
		List<Face> faces = new ArrayList<Face>();
		for (Face face : Face.values())
		{
			if (walls.get(face) == Wall.BLOCKED)
			{
				faces.add(face);
			}
		}
		return faces;
	}

	/**
	 * check if the wall can pass for the specific face
	 */
	public boolean canWallPass(Face face)
	{
		return (walls.get(face) == Wall.PASSED);
	}
}
